package com.jy.adscm.operation.pebase.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.pebase.bean.PeAttachment;
import com.jy.adscm.operation.pebase.mapper.mysql.PeAttachmentMapper;
import com.jy.adscm.operation.pebase.service.PeAttachmentService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id;
import org.springframework.stereotype.Service;

import javax.swing.text.AbstractDocument;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-08-19
 */
@Service
public class PeAttachmentServiceImpl extends ServiceImpl<PeAttachmentMapper, PeAttachment> implements PeAttachmentService {
    @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public List<PeAttachment> selectByDid(Integer did) {
        Wrapper<PeAttachment> wrapper=new EntityWrapper<>();
        wrapper.eq("did", did);
        List<PeAttachment> peAttachments = super.selectList(wrapper);
        for (PeAttachment peAttachment : peAttachments) {
            if (AdscmBaseUtils.getInstance().isNotEmpty( peAttachment.getUploader(),null)){
                JyUser jyUser = jyUserMapper.selectById(peAttachment.getUploader());
                peAttachment.setUploaderName(jyUser.getName());
            }
        }
        return peAttachments;
    }
}
